package com.yunfangdata.web.controller;

import com.yunfangdata.domain.Tracking;
import com.yunfangdata.query.TrackingQueryObject;
import com.yunfangdata.service.ITrackingService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("tracking")
public class TrackingController {
    @Autowired
    private ITrackingService trackingService;


    @RequiresPermissions("tracking:index")
    @PermissionName("学员跟踪首页")
    @RequestMapping("")
    public String index(){
        return "tracking/list";
    }
    @RequestMapping("list")
    @ResponseBody
    public PageResult list(TrackingQueryObject qo){
        return trackingService.query(qo);
    }

    @RequiresPermissions("tracking:list")
    @PermissionName("学员跟踪列表")
  @RequestMapping("save")
    @ResponseBody
    public JsonResult save(Tracking entity) {
        JsonResult result = new JsonResult();
        try{
            trackingService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return  result;
    }

    @RequiresPermissions("tracking:update")
    @PermissionName("学员跟踪更新")
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(Tracking entity) {
        JsonResult result = new JsonResult();
        try{
            trackingService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result = new JsonResult("更新操作失败");
        }
        return  result;
    }



    //审核
    @RequestMapping("changeState")
    @ResponseBody
    public  JsonResult changeSate(Long id){
        JsonResult result = new JsonResult();
        try {
            trackingService.changeState(id);
        }catch (Exception e){
            e.printStackTrace();
            result=new JsonResult("修改错误");
        }
        return result;

    }


}